import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/pages/circle/CircleListPage.dart';
import 'package:huajianshe_app/widget/RoundedUnderlineTabIndicator.dart';

class MyCirclesWidget extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _MyCirclesWidgetState();
  }
}

class _MyCirclesWidgetState extends BaseState<MyCirclesWidget> with SingleTickerProviderStateMixin {

  late TabController tabController;
  late PageController pageController;

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 2, vsync: this);
    pageController = PageController(initialPage: 0);
  }

  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }

  void onPageChange(int index) {
    tabController.animateTo(index);
  }

  @override
  Widget build(BuildContext context) {
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
      Padding(padding: EdgeInsets.symmetric(horizontal: 13, vertical: 6),
        child: TabBar(
          onTap: (index) { pageController.jumpToPage(index); },
          labelPadding: EdgeInsets.only(left: 6, right: 6, bottom: 3),
          indicatorWeight: 1,
          indicatorSize: TabBarIndicatorSize.label,
          indicator: RoundedUnderlineTabIndicator(
            insets: EdgeInsets.only(top: 0, bottom: -5),
            borderSide: BorderSide(width: 1, color: C.primary),
          ),
          isScrollable: true,
          controller: tabController,
          labelColor: C.gray333,
          unselectedLabelColor: C.gray999,
          labelStyle: TS(18, C.gray333, fontWeight: FontWeight.bold),
          unselectedLabelStyle: TS(14, C.gray999),
          tabs: [Text('我加入的'), Text('我创建的')]
      ),),
      D(),
      SizedBox(width: double.infinity, height: 300, child:
      PageView.builder(
          key: const Key('pageView'),
          itemCount: 2,
          onPageChanged: onPageChange,
          controller: pageController,
          // itemBuilder: (_, int index) => Text("1"),
          itemBuilder: (_, int index) => CircleListPage(type: index == 0 ? 1 : 2)
      ))
    ]);
  }
}